﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ContactCenter.Core.Common;

namespace ContactCenter.Core.DomainModel
{
    /// <summary>
    /// Domain entity that represents a customer.
    /// </summary>
    [Serializable]
    public class Customer
    {
        [Obsolete("For NH only",true)]
        public Customer()
        {
        }

        private Customer(string customerName)
        {
            CustomerName = customerName;
            InsertDate = DateTime.Today;
        }

        public static Customer Create(string customerName)
        {
            var customer = new Customer(customerName) { Addresses = new Collection<Address>() };
            return customer;
        }


        public virtual Customer ChangeCreditCard(CreditCard creditCard)
        {
            ValidationHelper.ValidateCreditCard(creditCard);
            CreditCard = creditCard;
            return this;
        }

        public virtual Customer ChangeContactInfo(ContactInfo contactInfo)
        {
            ValidationHelper.ValidateContactInfo(contactInfo);
            ContactInfo = contactInfo;
            return this;
        }

        public virtual Customer ChangeCustomerName(string customerName)
        {
            CustomerName = customerName;
            return this;
        }

        public virtual void AddAddress(Address address)
        {
            if (!Addresses.Contains(address))
            {
                Addresses.Add(address);
            }
        }

        public virtual void RemoveAddress(Address address)
        {
            if (Addresses.Contains(address))
            {
                Addresses.Remove(address);
            }
        }

        public virtual void RemoveAllAddresses()
        {
            if (Addresses.Count > 0)
            {
                Addresses.Clear();
            }
        }

        public virtual int Id { get; protected set; }
        public virtual string CustomerName { get; private set; }
        
        public virtual ICollection<Address> Addresses { get; protected set; }

        public virtual CreditCard CreditCard { get; private set; }
        public virtual ContactInfo ContactInfo { get; private set; }
        public virtual DateTime InsertDate { get; private set; }
    }
}
